
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="() => { searchData = {} }" searchConditionNum="6">
        <a-form-item class="table-search-item" label="机构号">
          <a-input v-model:value="searchData['agentNo']" placeholder="输入机构号" />
        </a-form-item>
      </GzSearchForm>
      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
      >
        <template #topBtnSlot>
          <a-button
            v-if="$access('ENT_DATA_REPORT_WELFARE_NEW_PROXY_EXPT')"
            type="primary"
            :disabled="exportShow"
            :loading="loading"
            @click="exportDataReports"
          >
            <template #icon>
              <ArrowUpOutlined />
            </template>
            导出
          </a-button>
        </template>
      </GzTable>
    </a-card>
  </page-header-wrapper>
</template>
  
  <script lang="ts" setup>
  import {$getAgentDetailList,$exportAgentDetailList} from '@/api/dataReports/welfareRevitalize/index'
  import { ref, reactive,getCurrentInstance } from 'vue'
  const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties
  
  const infoTableRef = ref()
 
  const loading = ref(false)
  let tableColumns = reactive([
    { key: 'agentNo', title: '网点编码', dataIndex: 'agentNo', fixed: 'left' },
    { key: 'agentName', title: '网点名称', dataIndex: 'agentName' },
    { key: 'pId', title: '网点归属区县编码', dataIndex: 'pId' },
    { key: 'pName', title: '区县机构', dataIndex: 'pName' },
    { key: 'totalResidueSyncMemberNum', title: '权益中心待召回会员', dataIndex: 'totalResidueSyncMemberNum' },
    { key: 'totalSyncMemberNum', title: '已召回会员', dataIndex: 'totalSyncMemberNum' },
    { key: 'activitySyncMemberNum', title: '焕活礼领取情况', dataIndex: 'activitySyncMemberNum' },
    { key: 'activitySyncMemberScoreNum', title: '领取福分数', dataIndex: 'activitySyncMemberScoreNum' },
  ])
  const searchData: any = ref({})
  const exportShow = ref(true)
  // 请求table接口数据
  function reqTableDataFunc(params: any) {
   
    return new Promise((resolve, reject) => {
      $getAgentDetailList({ ...params})
        .then((res: any) => {
          if(res.records.length === 0) {
            exportShow.value = true
          } else {
            exportShow.value = false
          }            
          resolve(res)
        })
        .catch((err: any) => {
          reject(err)
        })
    })
  }

  const exportDataReports = () =>{
    loading.value = true
    $exportAgentDetailList({...searchData.value}).then(res=>{
      loading.value = false
       $infoBox.message.success('导出成功')
    }).catch(()=>{
      loading.value = false
    })
  }

  // 搜索
  function searchFunc() {
    infoTableRef.value.refTable(true)
  }
  </script>